import React, {Component} from 'react';

import './index.less';

import language from '../../language';

const TableRowOperator = (props) => {
    const {
        tableId, 
        index,
        copyRow,
        cardTable: {
            getRowsByIndexs
        },
        deleteRow,
        pasteRow,
        addRow,
        insertRow
    } = props;

    let btnConf = props.button.getButtons();
    let delBtn, copyBtn, pasteBtn, insertBtn;
    btnConf.forEach(btn => {
        if (btn.key === 'DelLine') {
            delBtn = btn;
        } else if (btn.key === 'InsLine') {
            insertBtn = btn;
        } else if (btn.key === 'CopyLine') {
            copyBtn = btn;
        } else if (btn.key === 'PasteLine') {
            pasteBtn = btn;
        }
    })
    return (
        <div className="table-row-operator-wrapper">
            {delBtn ? <a
                href="javascript:void(0);"
                className="table-operator-btn"
                onClick={() => {
                    deleteRow(tableId, [index]);
                }}
            >
                {delBtn.title}{/* 国际化处理： 删除*/}
            </a> : null}
            {copyBtn ? <a
                href="javascript:void(0);"
                className="table-operator-btn"
                onClick={() => {
                    let data = getRowsByIndexs(tableId, [index]);
                    copyRow(tableId, data);
                }}
            >
                {copyBtn.title}{/* 国际化处理： 复制*/}
            </a> : null}
            {pasteBtn ? <a
                href="javascript:void(0);"
                className="table-operator-btn"
                onClick={() => {
                    pasteRow(tableId, index);
                }}
            >
                {pasteBtn.title}{/* 国际化处理： 粘贴*/}
            </a> : null}
            {insertBtn ? <a
                href="javascript:void(0);"
                className="table-operator-btn"
                onClick={() => {
                    insertRow(tableId, index);
                }}
            >
                {insertBtn.title}{/* 国际化处理： 插入*/}
            </a> : null}
        </div>
    );
}

export default TableRowOperator;
